'프로그래밍 언어'에 해당되는 글 4건
- 2018.05.24
- 2018.05.24
- 2018.05.24
- 2018.05.19
키보드로 입력받고 동적배열:10진수 동적을 참고
//변수값을 가지며(Scanner) 동적배열(ArrayList),for문의 경우 동적배열의 크기 이용
package javaproj; //키보드로 정수값을 입력받기,동적배열
import java.util.*;
public class HelloJava3 {
public static void main(String[] args) {
// TODO Auto-generated method stub
ArrayList<Integer> binArray=new ArrayList<Integer>();
System.out.print("10진수를 입력하시오:");
Scanner sc=new Scanner(System.in);
int num=sc.nextInt();
int i=0;
while(num!=0)
{
binArray.add(num%2);
num=num/2;
i++;
}
for(int j=binArray.size()-1;j>=0;j--)
{
System.out.print(binArray.get(j)+"");
}
}
}
자바프로그래밍 (입력받은)10진수를 2진수로 변환-정적배열 (0) | 2018.05.24 |
---|---|
자바 프로그래밍 10진수를 2진수로 변환-정적배열 (0) | 2018.05.24 |
C언어 Stack클래스의 구조 (0) | 2018.05.19 |
키보드로 입력받고 정적배열,length를 사용할 것. 예:for(int k=rest.length-1;~):
//변수값을 가지며(Scanner) 정적배열,for문의 경우 length를 사용
package javaproj; //키보드로 정수값을 입력받기,정적배열(단,length를 사용할 것)
import java.util.*;
public class HelloJava2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("10진수를 입력하시오");
Scanner sc=new Scanner(System.in);
int array[] =new int[10];
int num=sc.nextInt();
int i=0;
while(num!=0)
{
array[i]=num%2;
num=num/2;
i++;
}
for(int j=array.length-1;j>=0;j--)
{
System.out.println(array[j]);
}
}
}
자바프로그래밍 (입력받은)10진수를 2진수로 변환-동적배열 (0) | 2018.05.24 |
---|---|
자바 프로그래밍 10진수를 2진수로 변환-정적배열 (0) | 2018.05.24 |
C언어 Stack클래스의 구조 (0) | 2018.05.19 |
package javaproj; //상수값을 2진수로 만들기,정적배열
public class HelloJava2 {
public static void main(String[] args) {
// TODO Auto-generated method stub
int Value=100;
int i=0;
int [] rest=new int [20];
while(Value!=0)
{
rest[i]=Value%2;
Value=Value/2;
i++;
}
for(int j=19;j>=0;j--)
{
System.out.println(rest[j]);
}
}
}
자바프로그래밍 (입력받은)10진수를 2진수로 변환-동적배열 (0) | 2018.05.24 |
---|---|
자바프로그래밍 (입력받은)10진수를 2진수로 변환-정적배열 (0) | 2018.05.24 |
C언어 Stack클래스의 구조 (0) | 2018.05.19 |
.스택 클래스의 UML클래스 다이어그램
#include <iostream>
using namespace std;
class Stack
{
protected:
int m_size;
int m_top;
int ﹡m_buffer;
public:
void Initialize(int size=10);
void Remove All();
bool Push(int value);
bool Pop(int& value);
};
void Stack::Initialize(int size)
{
m_size=size;
m_top=-1;
m_buffer=new int[m_size];
memset=(m_buffer,0,sizeof(int)*m_size);
}
void Stack::Remove All()
{
m_size=0;
m_top=-1;
delete [] m_buffer;
m_buffer=NULL;
}
bool Stack::Push(int value)
{
if(m_top>=m_size-1) return false;
m_buffer[++m_top]=value;
return true;
}
bool Stack::Pop(int& value)
{
if(m_top<0) return false;
value=m_buffer[m_top--];
return true;
}
int main()
{
stack s1;
s1.Initialize(5);
while(s1.Push(rand()%100));
cout<<“s1에 저장된 데이터 : ”;
for(int 1=0;i<s1.m_size;i++)
cout<<s1.m_buffer[i]<<“ ”;
cout<<“\n”;
cout<<“s1에서 꺼낸 데이터 : ”;
int data;
while(s1.Pop(data))
cout<<data<<“ ”;
cout<<“\n”;
system(“pause”);
return 0;
}
자바프로그래밍 (입력받은)10진수를 2진수로 변환-동적배열 (0) | 2018.05.24 |
---|---|
자바프로그래밍 (입력받은)10진수를 2진수로 변환-정적배열 (0) | 2018.05.24 |
자바 프로그래밍 10진수를 2진수로 변환-정적배열 (0) | 2018.05.24 |