JAVA exercises,

Source: Internet
Author: User

JAVA exercises,

.

 

Import java. util. collections;

Public class T {

Public static void main (String [] args ){

System. out. println ("5 + 5 =" + 5 + 5 );
}
}

.

(1)

Import java. util. collections;
Public class G {
Public static void main (String [] args ){

Int a = 3, B;

B = a ++;

Sop ("a =" + a + ", B =" + B );

  Int a = 3, B;

  B = ++;

  Sop ("a =" + a + ", B =" + B );

}
}

(2 ).

Public class H
{
Public static void main (String [] args ){
Int a = 3, B;
B = ++;
System. out. println ("a =" + a + ", B =" + B );
}

}

.

 

 

Import java. util. collections;
Public class I {
Public static void main (String [] args ){
Short s = 3;
S = s + 4;
Sop ("s =" + s );
Short s = 3;
S + = 4;
Sop ("s =" + s );
}
}

.

 

Import java. util. collections;
Public class J {
Public static void main (String [] args ){
Sop (6 & 3 );
Sop (6 | 3 );
Sop (6 ^ 3 );
Sop (3 <2 );
Sop (3> 1 );
}
}

.

 

Import java. util. collections;
Public class K {
Public static void main (String [] args ){
Int x = 0, y;
Y = x> 1? 100:200;
Sop ("y =" + y );
}
}

(1). Output the larger integers in two integers

 

Public class M
{
Public static void main (String [] args ){
Int a = 1, B = 0, max;
Max = a> B? A: B;
System. out. println ("max =" + );
}

}

(2) output the largest integer among the three Integers

 

Public class M2
{
Public static void main (String [] args ){
Int a = 1, B = 0, c = 3, max;
Max = a> B? A: B;
Max = c> max? C: max;
System. out. println ("max =" + c );
}

}

.

 

Import java. util. collections;

Public class N {
Public static void main (String [] args ){
Int weekDay = 3;
If (weekDay = 1 ){
Sop ("Today is Monday ");
}
Else if (weekDay = 2 ){
Sop ("Today is Tuesday ");
}
Else if (weekDay = 3 ){
Sop ("Today is Wednesday ");
}
Else {
Sop ("No such day ");
}
Int month = 8;
}
}

(2) Use the associated if statement

Public class O
{
Public static void main (String [] args ){
Int weekDay = 3;
If (weekDay = 1 ){
System. out. println ("Today is Monday ");
} Else if (weekDay = 2 ){
System. out. println ("Today is Tuesday ");
} Else if (weekDay = 3 ){
System. out. println ("Today is Wednesday ");
} Else if (weekDay = 4 ){
System. out. println ("Today is Thursday ");
} Else if (weekDay = 5 ){
System. out. println ("Today is Friday ");
} Else if (weekDay = 6 ){
System. out. println ("Today is Saturday ");
} Else if (weekDay = 7 ){
System. out. println ("Today is August 7 ");
}
Else {
System. out. println ("No such day ");
}
}
}

Exercise.

Public class P
{
Public static void main (String [] args ){
Int month = 3;
If (month = 1 ){
System. out. println ("this month is winter ");
}
If (month = 2 ){
System. out. println ("this month is winter ");
}
If (month = 3 ){
System. out. println ("this month is Spring ");
}
If (month = 4 ){
System. out. println ("this month is Spring ");
}
If (month = 5 ){
System. out. println ("this month is Spring ");
}
If (month = 6 ){
System. out. println ("this month is summer ");
}
If (month = 7 ){
System. out. println ("this month is summer ");
}
If (month = 8 ){
System. out. println ("this month is summer ");
}
If (month = 9 ){
System. out. println ("this month is Autumn ");
}
If (month = 10 ){
System. out. println ("this month is Autumn ");
}
If (month = 11 ){
System. out. println ("this month is Autumn ");
}
If (month = 12 ){
System. out. println ("this month is winter ");
}

System. out. println (month );
}

}

7.

Import java. util. collections;
Public class CH {
Public static void main (String [] args ){
Int a = 84, B = 3;
Char option = '% ';
Switch (option)
{
Case '+ ':
System. out. println ("a + B =" + (a + B ));
Break;
Case '-':
System. out. println ("a-B =" + (a-B ));
Break;
Case '*':
System. out. println ("a * B =" + (a * B ));
Break;
Case '/':
System. out. println ("a/B =" + (a/B ));
Break;
Case '% ':
System. out. println ("a % B =" + (a % B ));
Break;
Default:
System. out. println ("a % B =" + (a % B ));
Break;
}
}
}

8.

Import java. util. collections;
Public class CH {
Public static void main (String [] args ){
Int x = 1;
Do {
Sop ("x =" + x );
X ++;
}
While (x <1 );
}
}

Import java. util. collections;
Public class CH {
Public static void main (String [] args ){
Int y = 1;
While (y <1 ){
Sop ("y =" + y );
Y ++;
}
}
}

9.

Import java. util. collections;
Public class CH {
Public static void main (String [] args ){
For (int x = 1; x <3; x ++)
{
Sop ("x =" + x );
}
}
}

9.

Import java. util. collections;

Public class CH {
Public static void main (String [] args ){
For (sop ("a"); sop ("B"); sop ("c ")
{
Sop ("d ");
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.