[ Team LiB ] 1 Basics of Java

[ Team LiB ] 2 Language Fundamentals 2.1 The following program will compile and run without errors: package com.acme; // Correct ordering of package and importstatements. import java.util.*; public class Exercise1 { int counter; // This is rather useless public static void main(String[] args) { // Correct main signature Exercise1 instance = new Exercise1(); instance.go(); } public void go() { int sum = 0; // We could just as well have written sum = 100// here and removed the if statement below. int i = 0; while (i<100) { if (i == 0) sum = 100; sum = sum + i; i++; } System.out.println(sum); } } 2.2 The following program will compile and run without errors: // Filename: Temperature.java/* Identifiers and keywords in Java are case-sensitive. Therefore, the case of the file name must match the class name, the keywords must all be written in lowercase. The name of the String class has acapital S. The main method must be static and take an array ofString objects as an argument. */ public class Temperature { public static void main(String[] args) { // Correct method signaturedouble fahrenheit = 62.5; // /* identifies the start of a "starred" comment. // */ identifies the end. /* Convert */ double celsius = f2c(fahrenheit); Page 641
Note: If you are looking for good and quality webspace to host and run your java application check professional java hosting services

Comments are closed.