Advanced Programming-Week2

Advanced Programming-Week2

以下程序仅供参考,因为编辑器原因,空格被过滤了,部分程序可能无法直接运行,请勿直接copy。

Summary

  1. Java程序的基本结构
  2. 输出
      1. 格式化输出 printf()/format()
      2. 带换行的输出 println()
      3. 对话框输出 JOptionPane.showMessageDialog();

Task1

public class work{
    public static void main(String [] args)
    {
        System.out.println("  //////// ");
        System.out.println(" |  O O  | ");
        System.out.println("(|   ^   |)");
        System.out.println(" |  - -  | ");
        System.out.println(" | |___| | ");
        System.out.println(" --------- ");
    }
}

Task2

public class work{
    public static void main(String [] args)
    {
        System.out.printf("%-12s Your Student ID\n","Stuendt ID: ");
        System.out.printf("%-12s Your Name","Name:");
        System.out.printf("%-12s Software Development\n","Course");
    }
}

Task3

public class work {
    public static void main(String [] args)
    {
        System.out.printf("*************************************\n",str);
        System.out.printf("* %s *\n","Patient/Client Management System");
        System.out.printf("*************************************\n",str);
        System.out.printf("* %-33s*\n","1. Record Consultation");
        System.out.printf("* %-33s*\n","2. Add a new Patient/Client");
        System.out.printf("* %-33s*\n","3. Refer Patient/Client");
        System.out.printf("* %-33s*\n","0. Exit system");
        System.out.printf("*************************************\n\n",str);
        System.out.println("Please enter your selection:");
    }
}

Task4

public class work
{
    public static void main(String[] args)
    {
        System.out.println("Success");
        System.out.print("Success ");
        System.out.println("Success");
        System.out.print("\nSuccess ");
    }
}

Task5

public class work
{
    public static void main(String [] args)
    {
        System.out.println("\\ is a backward slash");
        System.out.println("/ is a forward slash");
        System.out.print("To display a \\ ");
        System.out.print("you needto add an extra \\.");
        System.out.println();
        System.out.println("To display a \" place a \\ before the \"");
    }
}

Task6

public class work {
    public static void main(String [] args)
    {
        System.out.println("\"Quotes\"");
        System.out.println("Slashes \\//");
        System.out.println("How '\"confounding'\"\\\" it is!");
    }
}

Task7

部分空格被自动过滤了,大家可以参考这张图自己添加或者是重新编写。

public class work {
    public static void main(String [] args)
    {
        String ln1="(\\-\"\"\"-/)";
        String ln2="| |";
        String ln3="\\ ^ ^ / .-.";
        String ln4="\\_O_/ / /";
        String ln5="/' '\\/ |";
        String ln6="/ \\ |";
        String ln7="\\ ( ) / |";
        String ln8="/ \\_) (_/ \\ /";
        String ln9="| (\\-/) |";
        String ln10="\\ --^O^-- /";
        String ln11="\\ '.___.' /";
        String ln12=".' \\-=-/ '.";
        String ln13="/ /' '\\ \\";
        String ln14="(//./ \\.\\\\)";
        String ln15="'\"' '\"'";
        String ln16="\"Kangaroo\" by Anonymous";
        System.out.printf("%17s\n%16s\n%21s\n%20s\n%20s\n%20s\n%20s\n%20s\n%19s\n%19s\n%18s\n%19s\n%20s\n%21s\n%20s\n%24s\n",
        ln1,ln2,ln3,ln4,ln5,ln6,ln7,ln8,
        ln9,ln10,ln11,ln12,ln13,ln14,ln15,ln16);
    }
}

Task8

 

import javax.swing.*;
public class work {
    public static void main(String [] args)
    {
        JOptionPane.showMessageDialog(null,"This is my first Java program \n");
        JOptionPane.showMessageDialog(null,"but it won't be my last!");
    }
}

 

Task9

public class work{
    public static void main(String [] args)
    {
        System.out.println("\\2 + 3 + hello");
        System.out.print(2 + 3 + 3 + 2);
        System.out.println();
        System.out.println(2 + 3 + " hello");
        System.out.print(2 + " hello" + 3 + 4);
        System.out.print(3);
        System.out.println(2 + " hello" + 3 + 4);
        System.out.print(1 + "" + 3 + 4);
    }
}

Task10

 

import javax.swing.*;
public class work {
    public static void main(String [] args)
    {
        JOptionPane.showMessageDialog(null,"\"Computers are useless.\nThey can only give you answers.\", said Pablo Picasso");
    }
}

 

Task11

public class work{
    public static void main(String [] args)
    {
        System.out.println(4+6*3);
        System.out.println(6.0/3*7);
        System.out.println(18.0/2+14.0/2);
        System.out.println(16.0/2);
        System.out.println(17.0/2);
        System.out.println(28.0/5);
        System.out.println((2+3)*4);
        System.out.println(20.0/(4+1));
        System.out.println(3+4*5);
        System.out.println(1%8+10%3);
}
}

Task12

import javax.swing.*;
public class work{
    public static void main(String [] args)
    {
        int num=10;
        num=num*num*num;
        JOptionPane.showMessageDialog(null,num);
    }
}
暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇