0% found this document useful (0 votes)
2 views4 pages

Computer Test

The document contains multiple Java class examples demonstrating various programming concepts such as data types, arithmetic operations, control structures, loops, and user input handling. Each class includes a main method that executes specific tasks, such as calculating values, checking for leap years, printing patterns, and summing even numbers. The code snippets also illustrate common programming errors and syntax issues that need to be corrected for successful compilation and execution.

Uploaded by

graciemendoza140
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
2 views4 pages

Computer Test

The document contains multiple Java class examples demonstrating various programming concepts such as data types, arithmetic operations, control structures, loops, and user input handling. Each class includes a main method that executes specific tasks, such as calculating values, checking for leap years, printing patterns, and summing even numbers. The code snippets also illustrate common programming errors and syntax issues that need to be corrected for successful compilation and execution.

Uploaded by

graciemendoza140
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 4

1.

public class Student


{
public static void main(String[]args)
{
int rollno=5;
String name=Hasini;
float marks=80;

system.out.println=("Roll number:" +rollno);


system.out.println=("Name:" +name);
system.out.println=("Marks:"+marks);
}
}

2.public class Reactangle


{
public static void main(String[]args)
{
double length= 50;
double width=20;
}
double answer=length*width;

System.out.println("the answer is:" + answer);


}}

3. public class Primitivedatatypes


{
public static void main(String[] args)
{
int number = 50;
float decimalnum = 3.14;
double biggerDecimal = 1234567890.123456;
char character = 'a';
boolean isTrue = true;

System.out.println("Integer: " + number);


System.out.println("Float: " + decimalnum);
System.out.println("Double: " + biggerDecimal);
System.out.println("Character: " + character);
System.out.println("Boolean: " + isTrue);
}
}

5.(a * b) - (c / d) + e, where a = 10, b = 5, c = 20, d = 4, and e = 2.


(10*5)-(20/4)+2

public class Calculation {


public static void main(String[] args) {
int a = 10;
int b = 5;
int c = 20;
int d = 4;
int e = 2;

int result = (a * b) - (c / d) + e;

System.out.println("Result: " + result);


}
}

7. import java.util.*;
public class Largest
{
public static void main (String[] args)
{
Scanner sc=new Scanner(System.in)
int a,b,c,largest;
System.out.println("Enter the first number:");
a = sc.nextInt();
System.out.println("Enter the second number:");
b = sc.nextInt();
System.out.println("Enter the third number:");
c = sc.nextInt();

largest = c > (a > b ? a : b) ? c : ((a > b) ? a : b);


System.out.println("The largest number is: "+largest);
}}

9.
public class AccString
{
public static void main(String[]args)
int num=6;

if(num%2==0)
{
System.out.println("This num is even");
}
{
else
System.out.println("This num is odd");
}
}

10.
import java.util.Scanner;

public class LeapYearChecker


{
public static void main(String[] args) {
Scanner sc = new Scanner(System.in);
System.out.print("Enter year: ");
int year = sc.nextInt();
switch (year % 4) {
case 0:
if (year % 100 != 0 || year % 400 == 0) {
System.out.println(year + " is leap year.");
} else {
System.out.println(year + " is not leap year.");
}
break;
default:
System.out.println(year + " is not a leap year.");
break;
}
scanner.close;
}
}

11. public class NaturalNumbers


{
public static void main(String [] args) {
for (int i = 1; i <= 10; i++) {
System.out.print(i + " ");
}
}
}

12. public class SumofEvenNum


{
public static void main(String [] args) {
int sum = 0;
int number = 2;

while (number <= 100) {


sum += number;
number += 2;
}

System.out.println("The sum of even numbers from 1 to 100 is: " + sum);


}
}

13. public class SkipNum


{
public static void main(String [] args) {
for (int i = 1; i <= 10; i++) {
if (i == 5) {
continue;
}
System.out.print(i + " ");
}
}
}

14. import java.util.Scanner;

public class Integersnegative


{
public static void main(String [] args) {
Scanner sc = new Scanner(System.in);

System.out.println("Enter negative integers:");

while (true) {
int number = sc.nextInt();

if (number < 0) {
break;
}

System.out.println("You entered: " + number);


}

System.out.println("Loop ended.");
}
}

15.public class Pattern


{
public static void main(String [] args) {
int r = 5;

for (int i = 1; i <= r; i++) {


for (int h = 1; h <= i; h++) {
System.out.print("*");
}
System.out.println();

}}}

16.
public class Multipli
{
public static void main(String [ ] args) {

for (int i = 1; i<=5; i++) {


for (int y = 1; y <= 10; y++) {
System.out.println(i * y + "\t");
}
System.out.println();
}
}
}

You might also like